package message

import (
	"npxy-go/pkg/tcp"
)

type ConfigMessage struct {
	State      int8
	PortalPort uint16
	LocalPort  uint16
}

func (c *ConfigMessage) Decode(buf *tcp.Buffer) {
	c.State = buf.ReadInt8()
	c.LocalPort = buf.ReadUInt16()
	c.PortalPort = buf.ReadUInt16()
}

func (c *ConfigMessage) Encode(buf *tcp.Buffer) {
	buf.AddUInt16(c.PortalPort)
	buf.AddUInt16(c.LocalPort)
	buf.AddInt8(c.State)
	buf.AddInt8(int8(CONFIG))
}

func (c *ConfigMessage) Ok() bool {
	return c.State == 1
}
